package com.mxpio.erp.common.mes.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.mes.vo.ScanInfoVo;
import com.mxpioframework.jpa.annotation.Generator;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

@Data
@Table(name="MB_ERP_MES_SCAN_INFO")
@EqualsAndHashCode(callSuper=false)
@Entity
@Schema(description="生产报工操作信息表")
@AllArgsConstructor
@NoArgsConstructor
public class MesScanInfo extends BaseEntity {
    private static final long serialVersionUID = 1L;

	/**主键*/
	@Id
    @Generator
    @Schema(description = "主键")
    private String id;

    @Column(name = "BIZ_NO_")
    @Schema(description = "生产订单编号")
    private String bizNo;

    @Column(name = "ITEM_CODE_")
    @Schema(description = "产品编码")
    private String itemCode;

    @Column(name = "ITEM_NAME_")
    @Schema(description = "产品名称")
    private String itemName ;

    @Column(name = "BATCH_CODE_")
    @Schema(description = "批次号(工单号)")
    private String batchCode;

    @Column(name = "TASK_CODE_")
    @Schema(description = "工单工序任务编号")
    private String taskCode;

    @Column(name = "TASK_SN_CODE_")
    @Schema(description = "sn号")
    private String taskSnCode;

    @Column(name = "WORK_UNIT_CODE_")
    @Schema(description  = "作业单元编码")
    private String workUnitCode;

    @Column(name = "WORK_UNIT_NAME_" )
    @Schema(description  = "作业单元名称")
    private String workUnitName;

    @Column(name = "OPERATOR_")
    @Schema(description= "作业人")
    private String operator;

    @Column(name = "OPERATION_TYPE_")
    @Schema(description= "操作类型")
    private String operationType;

    @Column(name = "SCAN_TIME_")
    @Schema(description= "扫描时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date scanTime;

    /**工序顺序*/
    @Schema(description = "工序序号")
    @Column(name = "PROC_ORDER_")
    private Integer procOrder;
    /**工序代码*/
    @Schema(description = "工序编号")
    @Column(name = "PROC_CODE_")
    private String procCode;

    @Column(name = "PROC_GROUP_CODE_")
    @Schema(description  = "工序段编码")
    private String procGroupCode;

    @Column(name = "PROC_GROUP_NAME_" )
    @Schema(description  = "工序段名称")
    private String procGroupName;
    /**完工数量*/
    @Column(name = "COMPLETED_NUM_")
    @Schema(description = "完工数量")
    private Integer completedNum;
    /**报废数量*/
    @Column(name = "SCRAP_NUM_")
    @Schema(description = "报废数量")
    private Integer scrapNum;

    @Dict(dicCode = "MES_WORK_ORDER_STATUS")
    @Column(name = "BATCH_STATUS_" )
    @Schema(description = "批次（工单）状态")
    private String batchStatus;

    public MesScanInfo(ScanInfoVo scanInfoVO) {
        this.bizNo = scanInfoVO.getBizNo();
        this.batchCode = scanInfoVO.getBatchCode();
        this.taskCode = scanInfoVO.getTaskCode();
        this.taskSnCode = scanInfoVO.getTaskSnCode();
        this.workUnitCode = scanInfoVO.getWorkUnitCode();
        this.workUnitName = scanInfoVO.getWorkUnitName();
        this.procCode = scanInfoVO.getProcCode();
        this.procOrder = scanInfoVO.getProcOrder();
    }

    public MesScanInfo(ManufactureWorkOrderTask orderTask){
        this.procCode = orderTask.getProcCode();
        this.procOrder = orderTask.getProcOrder();
        this.taskCode = orderTask.getTaskCode();
        this.procGroupCode = orderTask.getProcGroupCode();
        this.procGroupName = orderTask.getProcGroupName();
        this.operationType = "工单工序任务扫描";
        this.setScanTime(orderTask.getReEndDate());
        this.completedNum = orderTask.getCompNum();
        this.scrapNum = orderTask.getScrapNum();
        this.operator = orderTask.getReEndUserId();
    }
}
